<template>
	<view>
		<div id="app">
			<div id="set_data">
				<div class="fill_word">
					<ul>
						<li>
							<div class="am-form-group"><i class="fa fa-thumbs-o-up" style="font-size:24px"></i>
								<input type="password" name="required" data-required="请输入原密码" class="mdn-input"
									v-model="fd.pwd" placeholder="原密码">
								<span class="mdn-bar"></span>
							</div>
						</li>
						<li>
							<div class="am-form-group"><i class="fa fa-thumbs-up" style="font-size:24px"></i>
								<input type="password" name="password" data-required="请输入新密码" id="password" onblur="validate_password(this.value)"
									class="mdn-input" v-model="fd.pw" placeholder="密码最少六位,由数字和字母组成"/>
								<span class="mdn-bar"></span>
							</div>
						</li>
						<li>
							<div class="am-form-group"><i class="fa fa-thumbs-up" style="font-size:24px"></i>
								<input type="password" name="password2" id="password2" data-required="请输入新密码"
									class="mdn-input" v-model="cs.password2" placeholder="请再次输入密码" onblur="validate_password2(this.value)" />
								<span class="mdn-bar"></span>
							</div>
						</li>
						<li><div style="color: red;">{{msg}}</div></li>
					</ul>
				</div>
			</div>
		</div>
		<button type="button" id="submitBtn" @click="submit()" class="yes"
			style="background-color: #61ac85;border: 1px solid #579572;">保存</button>
		</div>
	</view>
</template>

<script>
	import config from '@/config'
	export default {
		data() {
			return {
				fd: {
					pwd: '', //旧密
					pw: "" //新密	
				},
				cs:{
					password2:'',
				},
				msg:""

			}
		},
		methods: {
			backset_up: function() {
				uni.navigateTo({ //跳转设置页面
					url: 'set_up',
				});
			},
			submit: function() {
				var that = this;
				if ((this.fd.pwd.split(" ").join("").length == 0) || !this.fd.pwd) {
					that.msg="请输入原密码";
					return false;
				}
				if ((this.fd.pw.split(" ").join("").length == 0) || !this.fd.pw) {
					that.msg="请输入新密码";
					return false;
				}
				// if ((this.cs.password2.split(" ").join("").length == 0) || this.cs.password2!=this.fd.pw) {
				// 	that.msg="两次密码不一致";
				// 	return false;
				// }
				uni.request({
					url: `${config.baseUrl}/changen/chword?token=` + uni.getStorageSync('token'),
					method: 'POST',
					data: this.fd,
					success(r) {
						if (r.data.succ) {
							uni.navigateTo({
								url: '../../../pages/login/login'
							})
						}else{
							that.msg = "请重新输入原密码";
							console.log("发送失败");
						}
					}
				})
				
			},
		}
	}
</script>

<style>
	
</style>
